package com.lagou.edu.utils;

import com.lagou.edu.aop.ITransactionManager;
import com.lagou.edu.ioc.Autowired;
import com.lagou.edu.ioc.Component;

import java.sql.SQLException;


/**
* @author 应癫  事务管理器
*/
@Component("transactionManager")
public class TransactionManager implements ITransactionManager {

    @Autowired("connectionUtils")
    private ConnectionUtils connectionUtils;


    // 开启事务
     public void beginTransaction() throws SQLException {
       connectionUtils.getCurrentThreadConn().setAutoCommit(false);
     }
     // 提交事务
     public void commit() throws SQLException {
        connectionUtils.getCurrentThreadConn().commit();
     }
     // 回滚事务
     public void rollback() throws SQLException {
        connectionUtils.getCurrentThreadConn().rollback();
     }
}